package com.kitty.game.equip.service;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kitty.common.cache.RedisService;
import com.kitty.common.cache.entity.ActivityNumberSet;
import com.kitty.common.bean.PayGateWay;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.ServerService;
import com.kitty.game.activity.model.product.ActivityType;
import com.kitty.game.activity.service.ActivityService;
import com.kitty.game.activity.service.vip.SuperVipService;
import com.kitty.game.base.service.BagService;
import com.kitty.game.child.model.ChildInfo;
import com.kitty.game.common.BoosTitleDeal;
import com.kitty.game.config.Equip;
import com.kitty.game.config.NPC;
import com.kitty.game.config.Skill;
import com.kitty.game.confirm.model.InviteConfirm;
import com.kitty.game.confirm.model.RoleConfirm;
import com.kitty.game.drop.newservice.NewDropService;
import com.kitty.game.enter.TitleInfo;
import com.kitty.game.equip.EquipDataPool;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.equip.model.EquipBox;
import com.kitty.game.equip.model.RoleEquip;
import com.kitty.game.fight.service.OneThreadService;
import com.kitty.game.gm.GmCommandHandler;
import com.kitty.game.hunpo.service.HunPoService;
import com.kitty.game.map.service.MapService;
import com.kitty.game.npc.NpcDataPool;
import com.kitty.game.npc.message.RespNpcContent;
import com.kitty.game.npc.model.NpcButton;
import com.kitty.game.party.model.Party;
import com.kitty.game.party.service.PartyService;
import com.kitty.game.pet.model.Pet;
import com.kitty.game.pet.service.PetService;
import com.kitty.game.player.model.HunPoProp;
import com.kitty.game.player.model.PlayerExtendBox;
import com.kitty.game.player.model.PlayerProfile;
import com.kitty.game.role.model.Account;
import com.kitty.game.role.model.Invite;
import com.kitty.game.role.model.Role;
import com.kitty.game.role.service.AccountService;
import com.kitty.game.role.service.PayService;
import com.kitty.game.role.service.RoleService;
import com.kitty.game.skill.SkillDataPool;
import com.kitty.game.skill.model.RoleSkill;
import com.kitty.game.team.message.RespConfirm;
import com.kitty.game.team.message.RespMsg;
import com.kitty.game.titleManage.entity.TitleDetailInfo;
import com.kitty.game.titleManage.service.TitleInfoService;
import com.kitty.game.utils.CommonConst;
import com.kitty.game.utils.StringUtil;
import com.kitty.game.utils.TimeUtil;
import com.kitty.game.welfare.model.CommonFetchedData;
import com.kitty.game.wuhun.WuHunPoProp;
import com.kitty.game.wuhun.WuHunService_;
import com.kitty.game.wuhun.WuhunService;
import com.kitty.game.zhounianka.message.MiJingShiLianEntity;
import com.kitty.game.zhounianka.message.MiJingShiLianInfo;
import com.kitty.game.zhounianka.message.MsgMiJingShiLian;
import com.kitty.listener.EventDispatcher;
import com.kitty.listener.EventType;
import com.kitty.listener.event.PaySuccessEvent;
import com.kitty.common.model.Reason;
import com.kitty.mina.cache.DataCache;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.mina.message.MessagePusher;
import com.kitty.game.reward.service.RewardSetService;
import lombok.extern.slf4j.Slf4j;
import org.apache.mina.core.session.IoSession;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.pager.Pager;
import org.nutz.json.Json;
import org.nutz.lang.util.NutMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;

import static com.kitty.game.npc.model.NpcButton.*;
import static com.kitty.common.model.Reason.hdds_buy;
import static java.util.Calendar.DAY_OF_MONTH;


@Service
@Slf4j
public class HDDSService {
    //private WuHunService_ WWuHunService;
    @Autowired
    RoleService roleService;
    @Autowired
    MapService mapService;
    @Autowired
    EquipService equipService;
    @Autowired
    Dao dao;

    @Autowired
    RewardSetService rewardSetService;
    @Autowired
    NewDropService newDropService;
    @Autowired
    RedisService redisService;
    private CommonFetchedData roleLevelData;
    private CommonFetchedData ExpRate;//经验
    private CommonFetchedData daohangRate;//经验

    public void init() {
        //装载抽奖 NPC 配置信息。  后续还有可能装载更多。
        //20220312 先优化抽奖NPC的二标签
        NpcDataPool.npcButtonHandlers.put(hdds_leiji_lingqu.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).leiji_lingqu(npcButtonParam.getRole(), npcButtonParam.getNpc())));

        NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_70.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).level(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_rank_leiji.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).rankLeiji(npcButtonParam.getRole(), npcButtonParam.getNpc())));
        NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_gold.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).buyGold(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_money.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).buyMoney(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_cjxfs.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).buyCjxfs(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_cjxfs_10.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).buyCjxfs(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_zqhm.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).buyZqhm(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_cjcfs.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).buyCjcfs(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_cwdwd.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).buyCwdwd(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_gold_unlimit.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).getUnlimit(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        {
            // 整理装备
            NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_sort_equip.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).sortEquip(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            //获得未鉴定装备
            NpcDataPool.npcButtonHandlers.put(NpcButton.hdds_unknow_equip.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).unknowEquip(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        }
        {
            // 理财  hdds_licai
            NpcDataPool.npcButtonHandlers.put(hdds_licai.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).licai(npcButtonParam.getRole(), npcButtonParam.getNpc())));
            NpcDataPool.npcButtonHandlers.put(hdds_licai_88.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).licaiBuy(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_licai_588.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).licaiBuy(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_licai_1888.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).licaiBuy(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_licai_3888.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).licaiBuy(npcButtonParam.getRole(), npcButtonParam.getMsg())));

            NpcDataPool.npcButtonHandlers.put(hdds_licai_88_reward.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).licaiReward(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_licai_588_reward.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).licaiReward(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_licai_1888_reward.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).licaiReward(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_licai_3888_reward.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).licaiReward(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        }

        {
            NpcDataPool.npcButtonHandlers.put(hdds_menpai.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).menpai(npcButtonParam.getRole(), npcButtonParam.getNpc())));
            NpcDataPool.npcButtonHandlers.put(hdds_menpai1.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).changeMenpai(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_menpai2.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).changeMenpai(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_menpai3.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).changeMenpai(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_menpai4.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).changeMenpai(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_menpai5.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).changeMenpai(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        }
        {
            // 升级
            NpcDataPool.npcButtonHandlers.put(hdds_rank_level.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).roleLevel(npcButtonParam.getRole(), npcButtonParam.getNpc())));
//            NpcDataPool.npcButtonHandlers.put(hdds_rank_up_level.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).roleLevelHandle(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_rank_down_level.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).roleLevelHandle(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_child.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).child(npcButtonParam.getRole(), npcButtonParam.getNpc())));
            NpcDataPool.npcButtonHandlers.put(hdds_trans_yuanying.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).transChild(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            NpcDataPool.npcButtonHandlers.put(hdds_trans_xueying.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).transChild(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        }

        {
            // 魂魄突破
            NpcDataPool.npcButtonHandlers.put(hdds_rank_hunpo.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).hunpoxiaohao(npcButtonParam.getRole(), npcButtonParam.getNpc())));
            NpcDataPool.npcButtonHandlers.put(hdds_rank_hunpo_11.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).hunpoTupo(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            // 魂魄突破
            NpcDataPool.npcButtonHandlers.put(hdds_rank_wuhun.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).wuhunxiaohao(npcButtonParam.getRole(), npcButtonParam.getNpc())));
            NpcDataPool.npcButtonHandlers.put(hdds_rank_wuhun_11.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).wuhunTupo(npcButtonParam.getRole(), npcButtonParam.getMsg())));
            // 魂魄突破十二阶
            //    NpcDataPool.npcButtonHandlers.put(hdds_rank_hunpo_12.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).hunpoTupo(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        }

        NpcDataPool.npcButtonHandlers.put(hdds_invite_reward.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).getInviteReward(npcButtonParam.getRole(), npcButtonParam.getMsg())));

        // 坐骑升阶位
        NpcDataPool.npcButtonHandlers.put(hdds_zq_500.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).zq10(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_zq_1000.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).zq13(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_zq_1500.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).zq15(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_zq_2000.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).zq18(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_zq_3000.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).zq21(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_zq_4000.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).zq24(npcButtonParam.getRole(), npcButtonParam.getMsg())));

        // 物理技能升攻击目标
        NpcDataPool.npcButtonHandlers.put(hdds_jineng_0001.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).lp0001(npcButtonParam.getRole(), npcButtonParam.getNpc())));
        NpcDataPool.npcButtonHandlers.put(hdds_jineng_200.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).lp5(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_jineng_300.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).lp6(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_jineng_500.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).lp7(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_jineng_1000.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).lp8(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_jineng_1500.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).lp9(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_jineng_2000.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).lp10(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        // 法术技能升攻击目标
        NpcDataPool.npcButtonHandlers.put(hdds_fashu_0001.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).fs0001(npcButtonParam.getRole(), npcButtonParam.getNpc())));
        NpcDataPool.npcButtonHandlers.put(hdds_fashu_200.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).fs6(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_fashu_300.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).fs7(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_fashu_500.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).fs8(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_fashu_1000.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).fs9(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_fashu_2000.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).fs10(npcButtonParam.getRole(), npcButtonParam.getMsg())));

        NpcDataPool.npcButtonHandlers.put(hdds_leiji.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).leiji(npcButtonParam.getRole(), npcButtonParam.getNpc())));
        NpcDataPool.npcButtonHandlers.put(hdds_leijika.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).leijika(npcButtonParam.getRole(), npcButtonParam.getNpc())));
        NpcDataPool.npcButtonHandlers.put(hdds_cangbaotu.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).bycbt(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_cangbaotu_10.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).bycbt(npcButtonParam.getRole(), npcButtonParam.getMsg())));
        NpcDataPool.npcButtonHandlers.put(hdds_count.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).check(npcButtonParam.getRole(), npcButtonParam.getNpc())));
        NpcDataPool.npcButtonHandlers.put(menpo_buy_banggong.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).buyBg(npcButtonParam.getRole(), npcButtonParam.getNpc())));
        NpcDataPool.npcButtonHandlers.put(menpo_buy_banggong1.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).buyBg1(npcButtonParam.getRole(), npcButtonParam.getNpc())));
        NpcDataPool.npcButtonHandlers.put(hdds_linqu_chongzhi.getKey(), (npcButtonParam -> SpringUtils.getBean(HDDSService.class).linquChongzhi(npcButtonParam.getRole(), npcButtonParam.getNpc())));


        roleLevelData = dao.fetch(CommonFetchedData.class, CommonConst.role_level_upordown);
        if (roleLevelData == null) {
            roleLevelData = new CommonFetchedData();
            roleLevelData.setData(Json.toJson(new NutMap()));
            roleLevelData.setType(CommonConst.role_level_upordown);
            dao.insertOrUpdate(roleLevelData);
        }
        //ExpRate
        ExpRate = dao.fetch(CommonFetchedData.class, CommonConst.role_exp_rate);
        if (ExpRate == null) {
            ExpRate = new CommonFetchedData();
            ExpRate.setData("");
            ExpRate.setType(CommonConst.role_exp_rate);
            dao.insertOrUpdate(ExpRate);
        }
        daohangRate = dao.fetch(CommonFetchedData.class, CommonConst.role_daohang_rate);
        if (daohangRate == null) {
            daohangRate = new CommonFetchedData();
            daohangRate.setData("");
            daohangRate.setType(CommonConst.role_daohang_rate);
            dao.insertOrUpdate(daohangRate);
        }
    }

    private void unknowEquip(Role role, String msg) {
        if (role.getLevel() < 70 || role.getLevel() > 179) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("未鉴定装备最小70级，最高179"));
            return;
        }
        String level = role.getLevel() + "";
        if (level.length() < 2) {
            return;
        }
        roleService.subtractGold(role, 328, Reason.onekey_unkownEquip);
        if (level.length() == 2) {
            level = level.substring(0, 1) + "0";
        } else {
            level = level.substring(0, 2) + "0";
        }
        SpringUtils.getBean(GmCommandHandler.class).zhuangbei(role, Integer.parseInt(level));
    }


    public CommonFetchedData getExpRate() {
        return ExpRate;
    }

    public void setExpRate(CommonFetchedData expRate) {
        ExpRate = expRate;
    }

    public CommonFetchedData getDaohangRate() {
        return daohangRate;
    }

    public void setDaohangRate(CommonFetchedData daohangRate) {
        this.daohangRate = daohangRate;
    }

    private void sortEquip(Role role, String msg) {
        SpringUtils.getEquipService().resetEquipPos(role);
    }

    public void licaiBuy(Role role, String msg) {
        NutMap nutMap = role.getExtendBox().getLicai();
        NutMap data = nutMap.getAs(msg, NutMap.class);
        if (data == null) {
            HashMap<String, Integer> todayData = new HashMap();
            todayData.put(hdds_licai_88.getKey(), 88);
            todayData.put(hdds_licai_588.getKey(), 588);
            todayData.put(hdds_licai_1888.getKey(), 1888);
            todayData.put(hdds_licai_3888.getKey(), 3888);
            String str = TimeUtil.formatDate(new Date(), "yyyy-MM-dd");
            int sum = role.getTotalCharge();
            int cost = todayData.get(msg);
            if (sum < cost) {
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("累计充值还未达到#R" + cost + "#n，不能购买理财"));
                return;
            }
            //roleService.substractChargeScore(role, cost);
            roleService.subtractGold(role, cost, Reason.BUY_ITEM);
            data = NutMap.NEW();
            data.setv("start", new Date());
            nutMap.setv(msg, data);
            role.save();
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("购买理财成功。"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("不能重复购买理财。"));
        }
    }

    public void licaiReward(Role role, String msg) {
        HashMap<String, String> todayData = new HashMap();
        todayData.put(hdds_licai_88_reward.getKey(), hdds_licai_88.getKey());
        todayData.put(hdds_licai_588_reward.getKey(), hdds_licai_588.getKey());
        todayData.put(hdds_licai_1888_reward.getKey(), hdds_licai_1888.getKey());
        todayData.put(hdds_licai_3888_reward.getKey(), hdds_licai_3888.getKey());
        String key = todayData.get(msg);
        if (key == null) {
            return;
        }
        NutMap nutMap = role.getExtendBox().getLicai();
        NutMap data = nutMap.getAs(key, NutMap.class);
        if (data == null) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("未购买理财，不能领取"));
            return;
        }
        Date start = data.getTime("start");
        Date end = data.getTime("end");
        if (end != null) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(end);
            calendar.set(Calendar.HOUR_OF_DAY, 23);
            calendar.set(Calendar.MINUTE, 59);
            calendar.set(Calendar.SECOND, 59);
            if (new Date().before(calendar.getTime())) {
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("今天已经领取，不能重复领取理财"));
                return;
            }
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(start.getTime() + 15 * 24 * 60 * 60 * 1000));
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        if (new Date().after(calendar.getTime())) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("可以领取理财的时间已经结束，不能领取，结束时间为#R" + TimeUtil.formatDate(calendar.getTime())));
            return;
        }

        HashMap<String, Integer> reward = new HashMap();
        reward.put(hdds_licai_88.getKey(), 1888);
        reward.put(hdds_licai_588.getKey(), 8888);
        reward.put(hdds_licai_1888.getKey(), 19888);
        reward.put(hdds_licai_3888.getKey(), 48888);
        int value = reward.get(key);
        //增加积分
        //roleService.addRechargeScore(role, value);
        //增加元宝
        roleService.addGold(role, value, Reason.BUY_ITEM);
        data.setv("end", new Date());
        nutMap.setv(key, data);
        role.save();
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("领取理财成功"));
    }

    public void lingqurenwu_luobotaozi(Role role, NPC npc) {
        if (!role.getActivity().isLuobotaozi()) {
            role.getActivity().setLuobotaozi(true);
            MessagePusher.pushMessage((Role)role, new RespNotifyMiscEx("#R领取任务成功！！！"));
            this.roleService.luobotaozirenwu(role);
        } else {
            MessagePusher.pushMessage((Role)role, new RespNotifyMiscEx("#R已经领取任务 ，无须重复领取"));
        }
    }

    public void tijiaorenwu_luobotaozi(Role role, String msg) {
        int count = 10;
        short luobo_num;
        EquipBox equipBox;
        Iterator iterator;
        Map.Entry equipEntry;
        RoleEquip roleEquip;
        if (msg.equals("萝卜桃子大收集_tijlb")) {
            luobo_num = (short)this.equipService.getCount("萝卜", false, role);
            if(luobo_num < count){
                count = luobo_num;
            }
            equipService.delRoloEquip("萝卜", count, false, role);
            long jingyan = (long)(count * 1259371);
            if (jingyan > 2000000000L) {
                jingyan = 2000000000L;
            }
            MessagePusher.pushMessage((Role)role, new RespNotifyMiscEx(" 恭喜你！成功提交#R" + count + "#n个萝卜！！"));
            this.roleService.addExp(role, (int)jingyan, role.getLevel(), 0);
        } else if (msg.equals("萝卜桃子大收集_tijtz")) {
            luobo_num = (short)this.equipService.getCount("桃子", false, role);
            if(luobo_num < count){
                count = luobo_num;
            }
            equipService.delRoloEquip("桃子", count, false, role);




            MessagePusher.pushMessage((Role)role, new RespNotifyMiscEx(" 恭喜你！成功提交#R" + count + "#n个桃子！！"));
            this.roleService.addTao(role, count * 1000);
        } else if (msg.equals("萝卜桃子大收集_tijdtz")) {


            luobo_num = (short)this.equipService.getCount("大桃子", false, role);
            equipBox = role.getEquipBox();
            iterator = equipBox.getEquips().entrySet().iterator();

            while(iterator.hasNext()) {
                equipEntry = (Map.Entry)iterator.next();
                roleEquip = (RoleEquip)equipEntry.getValue();
                if (roleEquip.getPosition() < 200 && roleEquip.getPosition() >= 41 && roleEquip.getName().equals("大桃子")) {
                    this.equipService.delRoleEquip(roleEquip, role);
                }
            }

            MessagePusher.pushMessage((Role)role, new RespNotifyMiscEx(" 恭喜你！成功提交#R" + luobo_num + "#n个大桃子！！"));
            this.roleService.addRechargeScore(role, luobo_num * 888);
        }

    }

    public void tijiaorenwu_luobotaozi2(Role role, String msg) {
        short luobo_num;
        EquipBox equipBox;
        Iterator iterator;
        Map.Entry equipEntry;
        RoleEquip roleEquip;
        if (msg.equals("萝卜桃子大收集_tijdlb")) {
            luobo_num = (short)this.equipService.getCount("大萝卜", false, role);
            equipBox = role.getEquipBox();
            iterator = equipBox.getEquips().entrySet().iterator();

            while(iterator.hasNext()) {
                equipEntry = (Map.Entry)iterator.next();
                roleEquip = (RoleEquip)equipEntry.getValue();
                if (roleEquip.getPosition() < 200 && roleEquip.getPosition() >= 41 && roleEquip.getName().equals("大萝卜")) {
                    this.equipService.delRoleEquip(roleEquip, role);
                }
            }

            MessagePusher.pushMessage((Role)role, new RespNotifyMiscEx(" 恭喜你！成功提交#R" + luobo_num + "#n个大萝卜！！"));
            this.roleService.addRechargeScore(role, luobo_num * 888);
        }

    }

    public void licai(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        StringBuilder change = new StringBuilder();
        if (role.getExtendBox().getLicai().get(hdds_licai_88.getKey()) == null) {
            change.append("[" + hdds_licai_88.getKey() + "]");
        }
        if (role.getExtendBox().getLicai().get(hdds_licai_588.getKey()) == null) {
            change.append("[" + hdds_licai_588.getKey() + "]");
        }
        if (role.getExtendBox().getLicai().get(hdds_licai_1888.getKey()) == null) {
            change.append("[" + hdds_licai_1888.getKey() + "]");
        }
        if (role.getExtendBox().getLicai().get(hdds_licai_3888.getKey()) == null) {
            change.append("[" + hdds_licai_3888.getKey() + "]");
        }
        String content = "理财活动返积分.每个角色每档只能参与一次（可以一次全部参与）\n" +
                "88档位.当日充值达到#R88#n的用户可以花#R8888积分#n购买#R8888理财#n.15天每天可以领取#R1888积分#n 累计领取#R27088积分#n\n" +
                "588档位.当日充值达到#R588#n的用户可以花#R58888积分#n购买#R58888理财#n.15天每天可以领取#n8888积分 累计领取#R120288积分#n\n" +
                "1888档位.当日充值达到#R1888#n的用户可以花#R1888积分#n购买#R188888理财#n.15天每天可以领取#R19888积分#n 累计领取#R297088积分#n\n" +
                "3888档位.当日充值达到#R3888#n的用户可以花#R3888积分#n购买#R388888理财#n.15天每天可以领取#R48888积分#n 累计领取#R732088积分#n。" + change +
                "[" + hdds_licai_88_reward.getKey() + "]" +
                "[" + hdds_licai_588_reward.getKey() + "]" +
                "[" + hdds_licai_1888_reward.getKey() + "]" +
                "[" + hdds_licai_3888_reward.getKey() + "]" +
                "";
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    private void transChild(Role role, String msg) {
        ChildInfo childInfo = role.getChildInfo();
        if (childInfo.getType() <= 0) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("请先飞升"));
            return;
        }
        if (childInfo.getType() > 2) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("已经飞升，无法转换元婴"));
            return;
        }

        if (msg.contains("元婴")) {
            if (childInfo.getType() == 1) {
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("不能重复转换为元婴"));
                return;
            }
            childInfo.setState((byte) 1);
            roleService.getChild(role, (byte) 1);
        } else {
            if (childInfo.getType() == 2) {
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("不能重复转换为血婴"));
                return;
            }
            childInfo.setState((byte) 2);
            roleService.getChild(role, (byte) 2);

        }
        SpringUtils.getBroadcastService().sendUpdateAppear(role);

        roleService.subGoldOrCharge(role, 50000, Reason.BUY_ITEM);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("转换成功"));
    }

    private void child(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        String content = "转换元婴。[" + hdds_trans_yuanying.getKey() + "][" + hdds_trans_xueying.getKey() + "]";
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    private void roleLevelHandle(Role role, String msg) {
        SpringUtils.getBean(OneThreadService.class).addFightTask(0, new Runnable() {
            @Override
            public void run() {
                NutMap nutMap = Json.fromJson(NutMap.class, roleLevelData.getData());
                String roleId = role.getRoleId() + "";
                if (nutMap.get(roleId) == null) {
                    nutMap.setv(roleId, NutMap.NEW());
                }
                NutMap data = nutMap.getAs(roleId, NutMap.class);
                long time = data.getLong("time");
                Date date = new Date(time);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                if (calendar.get(DAY_OF_MONTH) != Calendar.getInstance().get(DAY_OF_MONTH)) {
                    // 不是今天，更新数据
                    data.clear();
                    data.setv("time", System.currentTimeMillis());
                }
                ChildInfo childInfo = role.getChildInfo();
                if (msg.contains("升一级")) {
                    int upcount = data.getInt("up");
//                    if (upcount >= 5) {
//                        MessagePusher.pushMessage(role, new RespNotifyMiscEx("每日最多升#R五级。"));
//                        return;
//                    }
                    if (role.isLockexp()) {
                        MessagePusher.pushMessage(role, new RespNotifyMiscEx("由于你锁定了经验，无法升级。"));
                        return;
                    }
                    //roleService.substractChargeScore(role, 288);
                    roleService.subtractGold(role, 4000000, Reason.BUY_ITEM);
                    data.setv("up", upcount + 1);
                    long needExp = role.isRealBody() ? roleService.getRoleUpgradeNeedExp(role.getLevel()) : childInfo.getUpgradeExp();
                    SpringUtils.getRoleService().addExp(role, (int) (needExp + 100), role.getLevel(), role.getPetBox().getFightPetId());
                } else {
                    int downcount = data.getInt("down");
//                    if (downcount >= 5) {
//                        MessagePusher.pushMessage(role, new RespNotifyMiscEx("每日最多降#R五级。"));
//                        return;
//                    }
                    Pet pet = role.getPetBox().getPetByPetId(role.getPetBox().getFightPetId());
                    if (pet != null && pet.getLevel() - role.getLevel() >= 15) {
                        MessagePusher.pushMessage(role, new RespNotifyMiscEx("参战宠物等级过高，请先让宠物休息。"));
                        return;
                    }
                    pet = role.getPetBox().getPetByPetId(role.getPetBox().getSupplyPetId());
                    if (pet != null && pet.getLevel() - role.getLevel() >= 15) {
                        MessagePusher.pushMessage(role, new RespNotifyMiscEx("掠阵宠物等级过高，请先让宠物休息。"));
                        return;
                    }
                    int[] poses = {10, 3, 2, 1, 4, 5, 6, 7};
                    for (int pos : poses) {
                        RoleEquip xiezi = equipService.getRoleEquipByPos(role, pos);
                        if (xiezi != null) {
                            Equip equip = EquipDataPool.getByName(xiezi.getName());
                            if (equip.getReq_level() > role.getLevel() - 1) {
                                MessagePusher.pushMessage(role, new RespNotifyMiscEx("请先卸下装备#R" + equip.getKey_name()));
                                return;
                            }
                        }
                    }
                    int subScore = Integer.parseInt(DataCache.REDIS_DATA.get("renwu_jiangji"));
                    roleService.substractChargeScore(role, subScore);
                    //roleService.substractChargeScore(role, 50000);//降级 每次5万积分111
                    //roleService.subtractGold(role,4000000,Reason.BUY_ITEM);
                    data.setv("down", downcount + 1);
                    if (role.isRealBody()) {
                        role.setLevel((short) (role.getLevel() - 1));
                        role.setExp(0);
                    } else {
                        childInfo.setLevel((short) (childInfo.getLevel() - 1));
                        childInfo.setExp(0);
                    }
                    role.setDex((short) 0);
                    role.setWiz((short) 0);
                    role.setStr((short) 0);
                    role.setCon((short) 0);
                    role.setLastAttrib(roleService.getLastAttributePoint(role));
                    role.setBasicAttrib();//升级重新设置基础属性
                    role.setCurrLife(role.getMaxLife());
                    role.setCurrMana(role.getMaxMana());
                    role.setMetal((short) (0));
                    role.setWood((short) (0));
                    role.setWater((short) (0));
                    role.setFire((short) (0));
                    role.setEarth((short) (0));
                    role.setLastPolar(roleService.getLastPolarPoint(role));
                    roleService.autoAddPoint(role, null);
                    roleService.autoPolar(role);
                    role.save();
                    MessagePusher.pushMessage(role, new RespNotifyMiscEx("降级成功！"));
                    SpringUtils.getBean(ServerService.class).getScheduledExecutorService().schedule(new Runnable() {
                        @Override
                        public void run() {
                            IoSession session = SessionUtils.getSession(role.getRoleId());
                            if (session != null) {
                                session.closeNow();
                            }
                        }
                    }, 1, TimeUnit.SECONDS);
                }
                //保存
                nutMap.setv(roleId, data);
                roleLevelData.setData(Json.toJson(nutMap));
                dao.insertOrUpdate(roleLevelData);
            }
        });
    }

    private void roleLevel(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        String renwu_jiangji = DataCache.REDIS_DATA.get("renwu_jiangji");
        String content = "降级一次需要消耗积分#R" + renwu_jiangji + "点"+"[" + hdds_rank_down_level.getKey() + "]";
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }


    private void hunpoTupo(Role role, String msg) {

        //int lv = Integer.parseInt(DataCache.REDIS_DATA.get("hunpo_lv"));
        String hunpo_wushang = DataCache.REDIS_DATA.get("hunpo_wushang");
        String hunpo_fashang = DataCache.REDIS_DATA.get("hunpo_fashang");
        String hunpo_fangyu = DataCache.REDIS_DATA.get("hunpo_fangyu");
        String hunpo_sudu = DataCache.REDIS_DATA.get("hunpo_sudu");
        String hunpo_item = DataCache.REDIS_DATA.get("hunpo_item");
        int hunpo_max = Integer.parseInt(DataCache.REDIS_DATA.get("hunpo_max"));

        HunPoService hunPoService = SpringUtils.getBean(HunPoService.class);
        HunPoProp hunPoProp = hunPoService.getHunPoProp(role);
        if (hunPoProp.getLevel() * 10 + hunPoProp.getLevelInner() < 110) {
            MessagePusher.pushMessage(role, new RespMsg("神魂境界未到#R十阶圆满#n，不能突破！"));
            return;
        }

        if (hunPoProp.getLevel() < hunpo_max) {
            boolean flag = false;
            //检测消耗 是否满足要求
            String[] split = hunpo_item.split("\\+");
            for (String s : split) {
                String[] split1 = s.split("-");
                if ("物品".equals(split1[0])) {
                    String name = split1[1];
                    int stoneNum = equipService.getCount(name, false, role);
                    if (stoneNum < Integer.parseInt(split1[2])) {
                        flag = true;
                        msg = name + "不足" + Integer.parseInt(split1[2]) + "个";
                    }
                } else if ("积分".equals(split1[0])) {
                    int jifen = Integer.parseInt(split1[1]);
                    if (role.getActivity().getRechargeScore() < jifen) {
                        flag = true;
                        msg = "积分不足" + Integer.parseInt(split1[1]);
                    }
                }
                if (flag) {
                    MessagePusher.pushMessage(role, new RespNotifyMiscEx(msg));
                    return;
                }
            }
            //扣除物品 积分
            for (String s : split) {
                String[] split1 = s.split("-");
                if ("物品".equals(split1[0])) {
                    String name = split1[1];
                    int count = Integer.parseInt(split1[2]);
                    equipService.delRoloEquip(name, count, true, role);
                    MessagePusher.pushMessage(role, new RespNotifyMiscEx("扣除" + name + count + "个成功"));
                } else if ("积分".equals(split1[0])) {
                    int jifen = Integer.parseInt(split1[1]);
                    roleService.substractChargeScore(role, jifen);
                }
            }



            if (hunPoProp.getLevel() >= hunpo_max) {
                MessagePusher.pushMessage(role, new RespMsg("神魂境界已经到达#Y" + hunpo_max + "#n阶圆满，不能再次突破！"));
                return;
            }
            hunPoProp.setLevel(hunPoProp.getLevel() + 1);
            hunPoProp.setPhyPower(hunPoProp.getPhyPower() + Integer.parseInt(hunpo_wushang));//物伤
            hunPoProp.setMagPower(hunPoProp.getMagPower() + Integer.parseInt(hunpo_fashang));//法伤
            hunPoProp.setDefense(hunPoProp.getDefense() + Integer.parseInt(hunpo_fangyu));//防御
            hunPoProp.setSpeed(hunPoProp.getSpeed() + Integer.parseInt(hunpo_sudu));//速度
            role.save();
            //发送属性
            roleService.sendExtraAttribute(role);
            //更新面板
            hunPoService.sendPanel(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("恭喜，魂魄成功突破至#Y"+hunPoProp.getLevel()+"#n阶！"));

        }else {
            MessagePusher.pushMessage(role, new RespMsg("神魂境界已经到达#Y" + hunpo_max + "#n阶圆满，不能再次突破！"));
        }

    }

    //武魂突破
    private void wuhunTupo(Role role, String msg) {

        //int lv = Integer.parseInt(DataCache.REDIS_DATA.get("hunpo_lv"));
        String wuhun_wushang = DataCache.REDIS_DATA.get("wuhun_wushang");
        String wuhun_fashang = DataCache.REDIS_DATA.get("wuhun_fashang");
        String wuhun_fangyu = DataCache.REDIS_DATA.get("wuhun_fangyu");
        String wuhun_sudu = DataCache.REDIS_DATA.get("wuhun_sudu");
        String wuhun_item = DataCache.REDIS_DATA.get("wuhun_item");
        int wuhun_max = Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_max"));

        WuhunService wuhunService = SpringUtils.getBean(WuhunService.class);
        WuHunPoProp wuHunPoProp = wuhunService.getWuHunProp(role);
        if (wuHunPoProp.getLevel() * 6 + wuHunPoProp.getLevelInner() < 36) {
            MessagePusher.pushMessage(role, new RespMsg("武魂境界未到#R大圆满#n，不能突破！"));
            return;
        }

        if (wuHunPoProp.getLevel() < wuhun_max) {
            boolean flag = false;
            //检测消耗 是否满足要求
            String[] split = wuhun_item.split("\\+");
            for (String s : split) {
                String[] split1 = s.split("-");
                if ("物品".equals(split1[0])) {
                    String name = split1[1];
                    int stoneNum = equipService.getCount(name, false, role);
                    if (stoneNum < Integer.parseInt(split1[2])) {
                        flag = true;
                        msg = name + "不足" + Integer.parseInt(split1[2]) + "个";
                    }
                } else if ("积分".equals(split1[0])) {
                    int jifen = Integer.parseInt(split1[1]);
                    if (role.getActivity().getRechargeScore() < jifen) {
                        flag = true;
                        msg = "积分不足" + Integer.parseInt(split1[1]);
                    }
                }
                if (flag) {
                    MessagePusher.pushMessage(role, new RespNotifyMiscEx(msg));
                    return;
                }
            }
            //扣除物品 积分
            for (String s : split) {
                String[] split1 = s.split("-");
                if ("物品".equals(split1[0])) {
                    String name = split1[1];
                    int count = Integer.parseInt(split1[2]);
                    equipService.delRoloEquip(name, count, true, role);
                    MessagePusher.pushMessage(role, new RespNotifyMiscEx("扣除" + name + count + "个成功"));
                } else if ("积分".equals(split1[0])) {
                    int jifen = Integer.parseInt(split1[1]);
                    roleService.substractChargeScore(role, jifen);
                }
            }



            if (wuHunPoProp.getLevel() >= wuhun_max) {
                MessagePusher.pushMessage(role, new RespMsg("武魂境界已经到达#Y" + wuhun_max + "#n阶圆满，不能再次突破！"));
                return;
            }
            wuHunPoProp.setLevel(wuHunPoProp.getLevel() + 1);
            wuHunPoProp.setPhyPower(wuHunPoProp.getPhyPower() + Integer.parseInt(wuhun_wushang));//物伤
            wuHunPoProp.setMagPower(wuHunPoProp.getMagPower() + Integer.parseInt(wuhun_fashang));//法伤
            wuHunPoProp.setDefense(wuHunPoProp.getDefense() + Integer.parseInt(wuhun_fangyu));//防御
            wuHunPoProp.setSpeed(wuHunPoProp.getSpeed() + Integer.parseInt(wuhun_sudu));//速度
            role.save();
            //发送属性
            roleService.sendExtraAttribute(role);
            //更新面板
            //WWuHunService.sendPanel(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("恭喜，武魂成功突破至#Y"+wuHunPoProp.getLevel()+"#n阶！"));

        }else {
            MessagePusher.pushMessage(role, new RespMsg("武魂境界已经到达#Y" + wuhun_max + "#n阶圆满，不能再次突破！"));
        }

    }

    private void hunpo(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        String content = "魂魄由十阶突破，#R十一阶，扣除元宝880W，属性增加28000物攻，法攻28000，速度520，防御15000[" + hdds_rank_hunpo_11.getKey() + "]";
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    //武魂消耗介绍
    public void wuhunxiaohao(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        StringBuffer sb = new StringBuffer("");
        sb.append("每次突破消耗 #R");
        WuhunService wuhunService = SpringUtils.getBean(WuhunService.class);
        WuHunPoProp wuHunPoProp = wuhunService.getWuHunProp(role);
        String wuhun_wushang = DataCache.REDIS_DATA.get("wuhun_wushang");
        String wuhun_fashang = DataCache.REDIS_DATA.get("wuhun_fashang");
        String wuhun_fangyu = DataCache.REDIS_DATA.get("wuhun_fangyu");
        String wuhun_sudu = DataCache.REDIS_DATA.get("wuhun_sudu");
        String wuhun_item = DataCache.REDIS_DATA.get("wuhun_item");
        int wuhun_max = Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_max"));
        String[] split = wuhun_item.split("\\+");
        for (String s : split) {
            String[] split1 = s.split("-");
            if ("物品".equals(split1[0])) {
                String name = split1[1];
                sb.append(name);
                sb.append(split1[2]);
                sb.append("个 ");
            } else if ("积分".equals(split1[0])) {
                int jifen = Integer.parseInt(split1[1]);
                sb.append("积分");
                sb.append(split1[1]);
            }
        }
        sb.append("#n 每次突破增加");

        sb.append("#Y物伤" + wuhun_wushang + "点 ");
        sb.append("法伤" + wuhun_fashang + "点 ");
        sb.append("防御" + wuhun_fangyu + "点 ");
        sb.append("速度" + wuhun_sudu + "点#n ");
        sb.append("最大武魂阶数#R" + wuhun_max + "阶#n");
        sb.append(" 当前武魂阶数#R" + wuHunPoProp.getLevel() + "阶#n");

        String content = sb.toString() + "[武魂突破至更高阶/武魂突破至更高阶]";
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    public void hunpoxiaohao(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        StringBuffer sb = new StringBuffer("");
        sb.append("每次突破消耗 #R");
        HunPoService hunPoService = SpringUtils.getBean(HunPoService.class);
        HunPoProp hunPoProp = hunPoService.getHunPoProp(role);
        String hunpo_wushang = DataCache.REDIS_DATA.get("hunpo_wushang");
        String hunpo_fashang = DataCache.REDIS_DATA.get("hunpo_fashang");
        String hunpo_fangyu = DataCache.REDIS_DATA.get("hunpo_fangyu");
        String hunpo_sudu = DataCache.REDIS_DATA.get("hunpo_sudu");
        String hunpo_item = DataCache.REDIS_DATA.get("hunpo_item");
        int hunpo_max = Integer.parseInt(DataCache.REDIS_DATA.get("hunpo_max"));
        String[] split = hunpo_item.split("\\+");
        for (String s : split) {
            String[] split1 = s.split("-");
            if ("物品".equals(split1[0])) {
                String name = split1[1];
                sb.append(name);
                sb.append(split1[2]);
                sb.append("个 ");
            } else if ("积分".equals(split1[0])) {
                int jifen = Integer.parseInt(split1[1]);
                sb.append("积分");
                sb.append(split1[1]);
            }
        }
        sb.append("#n 每次突破增加");

        sb.append("#Y物伤" + hunpo_wushang + "点 ");
        sb.append("法伤" + hunpo_fashang + "点 ");
        sb.append("防御" + hunpo_fangyu + "点 ");
        sb.append("速度" + hunpo_sudu + "点#n ");
        sb.append("最大神魂阶数#R" + hunpo_max + "阶#n");
        sb.append(" 当前神魂阶数#R" + hunPoProp.getLevel() + "阶#n");

        String content = sb.toString() + "[神魂突破至更高阶/神魂突破至更高阶]";
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    private void changeMenpai(Role role, String msg) {
        log.error("更换门派=={}=={}=={}", role.getRoleId(), role.getName(), msg);
        // 更换外观，更换技能，卸下武器
        short polar = 0;
        if (msg.contains("金")) {
            polar = 1;
        } else if (msg.contains("木")) {
            polar = 2;
        } else if (msg.contains("水")) {
            polar = 3;
        } else if (msg.contains("火")) {
            polar = 4;
        } else if (msg.contains("土")) {
            polar = 5;
        }
        if (polar == 0) {
            return;
        }
        if (polar == role.getPolar()) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("不能转换为#R当前所在门派"));
            return;
        }
        int oldPos = 1;
        EquipService equipService = SpringUtils.getBean(EquipService.class);
        RoleEquip resultEquip = equipService.getRoleEquipByPos(role, oldPos);
        if (resultEquip != null) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("请先卸下武器，否则不能转换门派！！"));
            return;
        }
        int oldPos2 = 11;
        RoleEquip resultEquip2 = equipService.getRoleEquipByPos(role, oldPos2);
        if (resultEquip2 != null) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("请先卸下第二套装备武器，否则不能转换门派！！"));
            return;
        }
        /*更换门派的积分*/
        int subScore = Integer.parseInt(DataCache.REDIS_DATA.get("zhuanhuan_menpai"));
        roleService.substractChargeScore(role, subScore);
        //roleService.subtractGold(role,888888, Reason.BUY_ITEM);
        role.setRoleIcon(mapService.heroIcon(role.getGender(), polar));
        role.setPolar(polar);
        // 更换角色图标
        List<PlayerProfile> playerProfiles = SpringUtils.getPlayerService().getPlayersBy(role.getSid());
        for (PlayerProfile playerProfile : playerProfiles) {
            if (playerProfile.getRoleId() == role.getRoleId()) {
                playerProfile.setRoleIcon(role.getRoleIcon());
                break;
            }
        }
        Collection<RoleSkill> collection = role.getSkillBox().getSkills().values();
        for (RoleSkill roleSkill : collection) {
            Skill skill = SkillDataPool.id2Skill.get(roleSkill.getSkillId());
            if (skill == null) {
                continue;
            }
            if (skill.getSkillJob() != 1
                    && skill.getSkillJob() != 2
                    && skill.getSkillJob() != 3
                    && skill.getSkillJob() != 4
                    && skill.getSkillJob() != 5) {
                continue;
            }
            int jieshu = skill.getJeishu();
            for (Map.Entry<Integer, Skill> entry : SkillDataPool.id2Skill.entrySet()) {
                if (jieshu == entry.getValue().getJeishu() && entry.getValue().getSkillJob() == polar && skill.getSkillType() == entry.getValue().getSkillType()) {
                    roleSkill.setSkillId(entry.getValue().getSkillId());
                    roleSkill.setName(entry.getValue().getSkillName());
                    break;
                }
            }
        }
        HashMap<Integer, RoleSkill> hashMap = new HashMap<>(role.getSkillBox().getSkills());
        for (Map.Entry<Integer, RoleSkill> entry : hashMap.entrySet()) {
            role.getSkillBox().getSkills().put(entry.getValue().getSkillId(), entry.getValue());
        }
        role.save();
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("转换门派成功，三秒后掉线，请重新登录！！！"));
        SpringUtils.getBean(ServerService.class).getScheduledExecutorService().schedule(new Runnable() {
            @Override
            public void run() {
                IoSession ioSession = SessionUtils.getSession(role.getRoleId());
                if (ioSession != null) {
                    ioSession.closeNow();
                }
            }
        }, 3, TimeUnit.SECONDS);
    }

    private void menpai(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        String zhuanhuan_menpai = DataCache.REDIS_DATA.get("zhuanhuan_menpai");
        String content = "更换门派消耗#R" + zhuanhuan_menpai + "积分[" + hdds_menpai1.getKey() + "][" + hdds_menpai2.getKey() + "][" + hdds_menpai3.getKey() + "][" + hdds_menpai4.getKey() + "][" + hdds_menpai5.getKey() + "]";
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    public void zhuanshengxiaohao(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        StringBuffer sb = new StringBuffer("");
        sb.append("转生需要消耗 #Y");
        int lv = Integer.parseInt(DataCache.REDIS_DATA.get("zhuansheng_lv"));
        String zhuansheng_item = DataCache.REDIS_DATA.get("zhuansheng_item");
        String zhuansheng_shuxing = DataCache.REDIS_DATA.get("zhuansheng_shuxing");
        int zhuansheng_max = Integer.parseInt(DataCache.REDIS_DATA.get("zhuansheng_max"));
        String[] split = zhuansheng_item.split("\\+");
        for (String s : split) {
            String[] split1 = s.split("-");
            if ("物品".equals(split1[0])) {
                String name = split1[1];
                sb.append(name);
                sb.append(split1[2]);
                sb.append("个 ");
            } else if ("积分".equals(split1[0])) {
                int jifen = Integer.parseInt(split1[1]);
                sb.append("积分");
                sb.append(split1[1]);
            }
        }
        sb.append("#n 每次转生增加所有相性#Y");
        //发送属性。
        JSONArray titleJars = JSONObject.parseArray(zhuansheng_shuxing);
        int attr = 0;
        int polor = 0;
        for (Object titleJar : titleJars) {
            JSONObject jsonObject = (JSONObject) titleJar;
            String field = jsonObject.getString("field");
            int num = jsonObject.getIntValue("value");
            if ("所有相性".equals(field)) {
                polor += num;
            }
            if ("所有属性".equals(field)) {
                attr += num;
            }
        }
        sb.append(polor + "#n点 ");
        sb.append("所有属性#Y" + attr + "#n点 ");
        sb.append("最大转生次数#Y" + zhuansheng_max + "#n次");
        sb.append(" 等级需达到#Y" + lv+ "#n级");

        String content = sb.toString() + "[开始转生/zhuansheng]";
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    private void getInviteReward(Role role, String msg) {
        role.setConfirm(new InviteConfirm(msg));
        msg = "确认#R当前角色领取邀请奖励#n？";
        RespConfirm respConfirm = new RespConfirm();
        respConfirm.setTips(msg);
        MessagePusher.pushMessage(role, respConfirm);
    }

    private void getUnlimit(Role role, String msg) {
        if (role.getTotalCharge() < 200) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("累计充值不到#R200#n，无法领取"));
            return;
        }
        roleService.addGold(role, 100000000, Reason.hdds_gold_unlimit);
    }

    private void fs0001(Role role, NPC npc) {
        StringBuffer sb = new StringBuffer("");
        for (int i = 0; i < 5; i++) {
            String lipo = DataCache.REDIS_DATA.get("wufa_" + (i + 1));
            String[] split = lipo.split("\\+");
            sb.append("#Y五法突破第" + (i + 1) + "次消耗#n");
            for (String s : split) {
                String[] split1 = s.split("-");
                if ("物品".equals(split1[0])) {
                    String name = split1[1];
                    sb.append(name);
                    sb.append(split1[2]);
                    sb.append("个");
                } else if ("积分".equals(split1[0])) {
                    int jifen = Integer.parseInt(split1[1]);
                    sb.append("积分");
                    sb.append(split1[1]);
                }
            }
        }
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());

        String content = sb.toString() + "[" + hdds_fashu_200.getKey() + "][" + hdds_fashu_300.getKey() + "][" + hdds_fashu_500.getKey() + "][" + hdds_fashu_1000.getKey() + "][" + hdds_fashu_2000.getKey() + "]";
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    private void fs6(Role role, String msg) {
        if (role.getPetBox().getFashu().contains(6)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        String wufa = DataCache.REDIS_DATA.get("wufa_1");
        String s = checkItemNum(wufa, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(wufa, role);
            role.getPetBox().getFashu().add(6);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,五法目标数成功增加到6个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void fs7(Role role, String msg) {
        if (role.getPetBox().getFashu().contains(7)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        if (!role.getPetBox().getFashu().contains(6)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你还没有升级到6目标数"));
            return;
        }
        String wufa = DataCache.REDIS_DATA.get("wufa_2");
        String s = checkItemNum(wufa, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(wufa, role);
            role.getPetBox().getFashu().add(7);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,五法目标数成功增加到7个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void fs8(Role role, String msg) {
        if (role.getPetBox().getFashu().contains(8)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        if (!role.getPetBox().getFashu().contains(7)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你还没有升级到7目标数"));
            return;
        }
        String wufa = DataCache.REDIS_DATA.get("wufa_3");
        String s = checkItemNum(wufa, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(wufa, role);
            role.getPetBox().getFashu().add(8);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,五法目标数成功增加到8个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void fs9(Role role, String msg) {
        if (role.getPetBox().getFashu().contains(9)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        if (!role.getPetBox().getFashu().contains(8)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你还没有升级到8目标数"));
            return;
        }
        String wufa = DataCache.REDIS_DATA.get("wufa_4");
        String s = checkItemNum(wufa, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(wufa, role);
            role.getPetBox().getFashu().add(9);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,五法目标数成功增加到9个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void fs10(Role role, String msg) {
        if (role.getPetBox().getFashu().contains(10)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        if (!role.getPetBox().getFashu().contains(9)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你还没有升级到9目标数"));
            return;
        }
        String wufa = DataCache.REDIS_DATA.get("wufa_5");
        String s = checkItemNum(wufa, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(wufa, role);
            role.getPetBox().getFashu().add(10);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,五法目标数成功增加到10个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void lp0001(Role role, NPC npc) {
        StringBuffer sb = new StringBuffer("");
        for (int i = 0; i < 6; i++) {
            String lipo = DataCache.REDIS_DATA.get("lipo_" + (i + 1));
            String[] split = lipo.split("\\+");
            sb.append("#Y力破突破第" + (i + 1) + "次消耗#n");
            for (String s : split) {
                String[] split1 = s.split("-");
                if ("物品".equals(split1[0])) {
                    String name = split1[1];
                    sb.append(name);
                    sb.append(split1[2]);
                    sb.append("个");
                } else if ("积分".equals(split1[0])) {
                    int jifen = Integer.parseInt(split1[1]);
                    sb.append("积分");
                    sb.append(split1[1]);
                }
            }
        }
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());

        String content = sb.toString() + "[" + hdds_jineng_200.getKey() + "][" + hdds_jineng_300.getKey() + "][" + hdds_jineng_500.getKey() + "][" + hdds_jineng_1000.getKey() + "][" + hdds_jineng_1500.getKey() + "][" + hdds_jineng_2000.getKey() + "]";
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }


    private void lp5(Role role, String msg) {
        if (role.getPetBox().getLipo().contains(5)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        String lipo = DataCache.REDIS_DATA.get("lipo_1");
        String s = checkItemNum(lipo, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(lipo, role);
            role.getPetBox().getLipo().add(5);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,力破千钧目标数成功增加到5个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void lp6(Role role, String msg) {
        if (role.getPetBox().getLipo().contains(6)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        if (!role.getPetBox().getLipo().contains(5)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你还没有升级到5目标数"));
            return;
        }
        String lipo = DataCache.REDIS_DATA.get("lipo_2");
        String s = checkItemNum(lipo, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(lipo, role);
            role.getPetBox().getLipo().add(6);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,力破千钧目标数成功增加到6个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void lp7(Role role, String msg) {
        if (role.getPetBox().getLipo().contains(7)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        if (!role.getPetBox().getLipo().contains(6)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你还没有升级到6目标数"));
            return;
        }
        String lipo = DataCache.REDIS_DATA.get("lipo_3");
        String s = checkItemNum(lipo, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(lipo, role);
            role.getPetBox().getLipo().add(7);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,力破千钧目标数成功增加到7个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void lp8(Role role, String msg) {
        if (role.getPetBox().getLipo().contains(8)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        if (!role.getPetBox().getLipo().contains(7)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你还没有升级到7目标数"));
            return;
        }
        String lipo = DataCache.REDIS_DATA.get("lipo_4");
        String s = checkItemNum(lipo, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(lipo, role);
            role.getPetBox().getLipo().add(8);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,力破千钧目标数成功增加到8个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void lp9(Role role, String msg) {
        if (role.getPetBox().getLipo().contains(9)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        if (!role.getPetBox().getLipo().contains(8)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你还没有升级到8目标数"));
            return;
        }
        String lipo = DataCache.REDIS_DATA.get("lipo_5");
        String s = checkItemNum(lipo, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(lipo, role);
            role.getPetBox().getLipo().add(9);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,力破千钧目标数成功增加到9个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void lp10(Role role, String msg) {
        if (role.getPetBox().getLipo().contains(10)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你已经突破到此阶段了"));
            return;
        }
        if (!role.getPetBox().getLipo().contains(9)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你还没有升级到9目标数"));
            return;
        }
        String lipo = DataCache.REDIS_DATA.get("lipo_6");
        String s = checkItemNum(lipo, role);
        if (StringUtil.isEmpty(s)) {
            //roleService.substractChargeScore(role, 20000);
            diffItemNum(lipo, role);
            role.getPetBox().getLipo().add(10);
            role.save();
            roleService.sendExtraAttribute(role);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜,力破千钧目标数成功增加到10个"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx(s));
        }
    }

    private void zq24(Role role, String msg) {
        if (!hasZuoqi(role)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("没有八阶坐骑"));
            return;
        }
        if (!role.getPetBox().getZuoqi().contains(21)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("请先升到21阶"));
            return;
        }
        roleService.substractChargeScore(role, 4000);
        role.getPetBox().getZuoqi().add(24);
        role.save();
        loadZQ(role);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("坐骑已经升至24阶"));
    }

    private void zq21(Role role, String msg) {
        if (!hasZuoqi(role)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("没有八阶坐骑"));
            return;
        }
        if (!role.getPetBox().getZuoqi().contains(18)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("请先升到18阶"));
            return;
        }
        roleService.substractChargeScore(role, 3000);
        role.getPetBox().getZuoqi().add(21);
        role.save();
        loadZQ(role);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("坐骑已经升至21阶"));
    }

    private void zq18(Role role, String msg) {
        if (!hasZuoqi(role)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("没有八阶坐骑"));
            return;
        }
        if (!role.getPetBox().getZuoqi().contains(15)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("请先升到15阶"));
            return;
        }
        roleService.substractChargeScore(role, 2000);
        role.getPetBox().getZuoqi().add(18);
        role.save();
        loadZQ(role);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("坐骑已经升至18阶"));
    }

    private void zq15(Role role, String msg) {
        if (!hasZuoqi(role)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("没有八阶坐骑"));
            return;
        }
        if (!role.getPetBox().getZuoqi().contains(13)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("请先升到13阶"));
            return;
        }
        roleService.substractChargeScore(role, 1500);
        role.getPetBox().getZuoqi().add(15);
        role.save();
        loadZQ(role);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("坐骑已经升至15阶"));
    }

    private void zq13(Role role, String msg) {
        if (!hasZuoqi(role)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("没有八阶坐骑"));
            return;
        }
        if (!role.getPetBox().getZuoqi().contains(10)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("请先升到10阶"));
            return;
        }
        roleService.substractChargeScore(role, 1000);
        role.getPetBox().getZuoqi().add(13);
        role.save();
        loadZQ(role);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("坐骑已经升至13阶"));
    }

    private void zq10(Role role, String msg) {
        if (!hasZuoqi(role)) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("没有八阶坐骑"));
            return;
        }
        roleService.substractChargeScore(role, 500);
        role.getPetBox().getZuoqi().add(10);
        role.save();
        loadZQ(role);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("坐骑已经升至10阶"));
    }

    private void loadZQ(Role role) {
        PetService petService = SpringUtils.getPetService();
        List<Pet> pets = petService.getPetList(role);
        for (Pet pet : pets) {
            if (pet.getRank() >= 8) {
                petService.loadPet(role, pet);
            }
        }
    }

    private boolean hasZuoqi(Role role) {
        for (Pet pet : role.getPetBox().getAllPets().values()) {

            if (pet.getName().equals("北斗天蓬")) {
                return true;
            }
            if (pet.getName().equals("九尾仙狐")) {
                return true;
            }
            if (pet.getName().equals("至尊太极熊")) {
                return true;
            }
            if (pet.getName().equals("墨麒麟")) {
                return true;
            }
            if (pet.getName().equals("太极熊")) {
                return true;
            }
        }
        return false;
    }

    private void buyCwdwd(Role role, String msg) {
        roleService.substractChargeScore(role, 1);
        SpringUtils.getEquipService().addMall("宠物顿悟丹", true, role, 10);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("购买宠物顿悟丹成功！！"));
    }

    private void buyBg1(Role role, NPC npc) {
        Party party = SpringUtils.getPartyService().getParty(role.getPartyId());
        if (party == null) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("没有帮派，不能购买帮贡！！！"));
            return;
        }
        roleService.substractChargeScore(role, 10);
        SpringUtils.getBean(PartyService.class).addContrib(role, 3000);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("购买帮贡成功！！"));
    }

    //充值卡，累计奖励
    public void linquChongzhiKa(Role role) {
        if (role == null) {
            return;
        }
        boolean flag = false;
        int leijimoney = role.getExtendBox().getTotalChargeCard();
        List leiji = role.getExtendBox().getLeijikalingqu();
        List<ActivityNumberSet.RewardSet> rewardList = RewardSetService.rewardMapByLeijika;
        for (ActivityNumberSet.RewardSet rewardSet : rewardList) {
            int money = rewardSet.getMoney();
            if (leijimoney < money) {
                continue;
            }
            if (leiji.contains(rewardSet.getMoney())) {
                continue;
            }
            flag = true;
            for (String s : rewardSet.getRemake().split("\\+")) {
                newDropService.addRewardTask(role, s, rewardSet.getBeizhu());
            }
            leiji.add(rewardSet.getMoney());
        }
        if (flag) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("充值卡已经达到累计金额领取充值卡奖励成功，奖励已经自动发放到背包！！"));
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("充值卡使用成功，当前充值卡总累计：" + leijimoney + " 金额达到可奖励阶段系统会自动发放，具体各阶段金额奖励请到充值卡奖励npc处查看"));
        }
    }

    public void getChangeAll() {
        AccountService accountService = SpringUtils.getBean(AccountService.class);
        try {
            List<PayGateWay> list = accountService.getAllPayGateWay();
            for (PayGateWay payGateWay : list) {
                sendChongzhi(payGateWay);
            }
        } catch (Exception e) {

        }

    }

    private void sendChongzhi(PayGateWay payGateWay) {
        AccountService accountService = SpringUtils.getBean(AccountService.class);
        //获取在线角色
        String account = payGateWay.getAccount();
        List<Account> query = dao.query(Account.class, Cnd.where("username", "=", account));
        if (query != null && query.size() > 0) {
            String id = query.get(0).getId();
            List<Role> list = dao.query(Role.class, Cnd.where("sid", "=", id));
            for (Role role2 : list) {
                boolean b = DataCache.ONLINE_ROLES.containsKey(role2.getUid());
                if (b) {
                    Role role = DataCache.ONLINE_ROLES.get(role2.getUid());
                    PlayerExtendBox extendBox = role.getExtendBox();
                    if (extendBox == null) {
                        role.setExtendBox(new PlayerExtendBox());
                    }
                    int money = (int) payGateWay.getMoney();
                    log.info("发送充值中，充值账号：{},充值角色：{},充值金额：{}", account, role.getName(), money);
                    EventDispatcher.getInstance().fireEvent(new PaySuccessEvent(EventType.PAY_SUCESS, role, payGateWay.getRmb(), 0));
                    payGateWay.setState(1);
                    accountService.update(payGateWay);
                    SpringUtils.getBean(NewChargeActivityService.class).addChongzhiRankCount(role, money);
                    //这里去赠送单笔充值达到多少的 奖励。
                    if (RewardSetService.rewardMapByDanBi.containsKey(money)) {
                        List<ActivityNumberSet.RewardSet> rewards = RewardSetService.rewardMapByDanBi.get(money);
                        for (ActivityNumberSet.RewardSet reward : rewards) {
                            for (String s : reward.getRemake().split("\\+")) {
                                newDropService.addRewardTask(role, s, reward.getBeizhu());
                            }
                        }
                    }
                    //这里赠送单笔充值的称号。 如果没有这个称号就赠送， 有则跳过
                    TitleDetailInfo titleDetailInfo = TitleInfoService.danbiMapByGroup.get(money);
                    if (titleDetailInfo != null) {
                        TitleInfo titleInfo = new TitleInfo();
                        titleInfo.setType(titleDetailInfo.getName());
                        titleInfo.setTitle(titleDetailInfo.getName());
                        SpringUtils.getRoleService().addTitle(role, titleInfo);
                    }

                    //自动发放累计充值奖励
                    leiji_lingqu(role, null);
                    MessagePusher.pushMessage(role, new RespNotifyMiscEx("领取充值成功！！"));
                    SpringUtils.getBean(SuperVipService.class).changeSuperVip(role);
                    //这里去赠送每日累计充值奖励
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                    String format = sdf.format(new Date());
                    redisService.setIsNull("mrlj_" + format + role.getId(), money, 60 * 60 * 24);
                    int mrlj = redisService.getInt("mrlj_" + format + role.getId());
                    String mgs = DataCache.REDIS_DATA.get("mrlj_task_reward");
                    JSONArray jars = JSONObject.parseArray(mgs);
                    for (Object jar : jars) {
                        JSONObject obj = (JSONObject) jar;
                        int money1 = obj.getIntValue("money");
                        if(mrlj >= money1  && !extendBox.getMrTotalContent().contains(money1)){
                            String reward = obj.getString("reward");
                            for (String s : reward.split("\\+")) {
                                newDropService.addRewardTask(role,s,"");
                            }
                            extendBox.getMrTotalContent().add(money1);
                            MessagePusher.pushMessage(role, new RespNotifyMiscEx("获得每日累计充值"+money1+"阶段奖励！！"));
                        }
                    }
//                    //如果今日充值 大于300，并且没有领取过，则增加一十点相性。
//                    if (mrlj >= 300 && !format.equals(role.getExtendBox().getMrlj())) {
//                        if (role.getExtendBox().getPolorNum() < 100) {
//                            role.getExtendBox().setPolorNum(role.getExtendBox().getPolorNum() + 10);
//                            role.getExtendBox().setMrlj(format);
//                            //赠送相性，刷新属性
//                            roleService.sendExtraAttribute(role);
//                        }
//                    }
                    //刷新任务
                    roleService.mrljAddPolorTask(role);

                }
            }
        }


    }

    private void linquChongzhi(Role role, NPC npc) {
        AccountService accountService = SpringUtils.getBean(AccountService.class);
        Account account = accountService.getAccount(role.getSid());
        if (account == null) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("账号不存在"));
            return;
        }
        List<PayGateWay> list = accountService.getPayGateWay(account.getUsername());
        if (list == null || list.size() <= 0) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("没有未领取的充值！！"));
            return;
        }
        PayService payService = SpringUtils.getBean(PayService.class);
        for (PayGateWay payGateWay : list) {
            EventDispatcher.getInstance().fireEvent(new PaySuccessEvent(EventType.PAY_SUCESS, role, payGateWay.getRmb(), 0));
            payGateWay.setState(0);
            accountService.update(payGateWay);
            int money = (int) payGateWay.getMoney();
            payGateWay.setState(1);
            accountService.update(payGateWay);
            SpringUtils.getBean(NewChargeActivityService.class).addChongzhiRankCount(role, money);
            //这里去赠送单笔充值达到多少的 奖励。
            if (RewardSetService.rewardMapByDanBi.containsKey(money)) {
                List<ActivityNumberSet.RewardSet> rewards = RewardSetService.rewardMapByDanBi.get(money);
                for (ActivityNumberSet.RewardSet reward : rewards) {
                    for (String s : reward.getRemake().split("\\+")) {
                        newDropService.addRewardTask(role, s, reward.getBeizhu());
                    }
                }
            }
            //这里赠送单笔充值的称号。 如果没有这个称号就赠送， 有则跳过
            TitleDetailInfo titleDetailInfo = TitleInfoService.danbiMapByGroup.get(money);
            if (titleDetailInfo != null) {
                TitleInfo titleInfo = new TitleInfo();
                titleInfo.setType(titleDetailInfo.getName());
                titleInfo.setTitle(titleDetailInfo.getName());
                SpringUtils.getRoleService().addTitle(role, titleInfo);
            }
            //这里去赠送每日累计充值奖励
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String format = sdf.format(new Date());
            redisService.setIsNull("mrlj_" + format + role.getId(), money, 60 * 60 * 24);
            int mrlj = redisService.getInt("mrlj_" + format + role.getId());
            //如果今日充值 大于300，并且没有领取过，则增加一十点相性。
            if (mrlj >= 300 && !format.equals(role.getExtendBox().getMrlj())) {
                if (role.getExtendBox().getPolorNum() < 100) {
                    role.getExtendBox().setPolorNum(role.getExtendBox().getPolorNum() + 10);
                    role.getExtendBox().setMrlj(format);
                    //赠送相性，刷新属性
                    roleService.sendExtraAttribute(role);
                }
            }
            //刷新任务
            roleService.mrljAddPolorTask(role);
        }
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("领取充值成功！！"));
        SpringUtils.getBean(SuperVipService.class).changeSuperVip(role);
    }

    /*修改累计充值*/
    private void leiji_lingqu(Role role, NPC npc) {
        if (role == null) {
            return;
        }
        boolean flag = false;
        int leijimoney = role.getTotalCharge();
        List leiji = role.getExtendBox().getLeijilingqu();
        List<ActivityNumberSet.RewardSet> rewardList = RewardSetService.rewardMapByLeiji;
        for (ActivityNumberSet.RewardSet rewardSet : rewardList) {
            int money = rewardSet.getMoney();
            if (leijimoney < money) {
                //MessagePusher.pushMessage(role, new RespMsg("当前充值不足！"));
                continue;
            }
            if (leiji.contains(rewardSet.getMoney())) {
                //MessagePusher.pushMessage(role, new RespMsg("当前累计已经领取！"));
                continue;
            }
            flag = true;
            for (String s : rewardSet.getRemake().split("\\+")) {
                newDropService.addRewardTask(role, s, rewardSet.getBeizhu());
            }
            leiji.add(rewardSet.getMoney());
        }
        if (flag) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("领取充值成功！！"));
        } else {
            MessagePusher.pushMessage(role, new RespMsg("当前暂无可领取累计！"));
        }
    }

    private void buyBg(Role role, NPC npc) {
        roleService.substractChargeScore(role, 1);
        SpringUtils.getBean(PartyService.class).addContrib(role, 300);
    }

    private void check(Role role, NPC npc) {
        // R查询上古星次数
        ActivityService activityService = SpringUtils.getActivityService();
        int count = activityService.getRemainCount(role, ActivityType.SEAL_BOSS);
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("剩余上古万年#R" + count + "次#n");
//        count = activityService.getRemainCount(role, ActivityType.SEAL_BOSS_wannian);
//        stringBuilder.append("剩余万年#R"+count+"次#n");
        count = activityService.getRemainCount(role, ActivityType.XING_GUAN_tian);
        stringBuilder.append("剩余天星#R" + count + "次#n");
        count = activityService.getRemainCount(role, ActivityType.XING_GUAN_di);
        stringBuilder.append("剩余地星#R" + count + "次#n");
        MessagePusher.pushMessage(role, new RespNotifyMiscEx(stringBuilder.toString()));
    }

    private void bycbt(Role role, String msg) {
        short pos = SpringUtils.getBean(BagService.class).getPos(role, false);
        if (pos <= 0) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("背包已满"));
            return;
        }
        if (msg.contains("10积分")) {
            roleService.substractChargeScore(role, 10);
            SpringUtils.getEquipService().addMall("特级藏宝图", true, role, 10);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("购买特级藏宝图成功"));
        } else {
            roleService.substractChargeScore(role, 1);
            SpringUtils.getEquipService().addMall("特级藏宝图", true, role, 1);
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("购买特级藏宝图成功"));
        }

    }


    private void leiji(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setAttrib((byte) 1);
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        respNpcContent.setContent("累计充值：#R" + role.getTotalCharge() + "[离开]");
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    private void leijika(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setAttrib((byte) 1);
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        respNpcContent.setContent("充值卡累计：#R" + role.getExtendBox().getTotalChargeCard() + "[离开]");
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    /*
     *  活动大使  按钮
     */
    public String point(Role role) {
        String head = "中洲大陆的活动在此尽收眼底，欢迎各路豪杰前来参加！";
        String content = head +
                "[" + hdds_rank_hunpo.getKey() + "]" +   //魂魄突破
                "[" + hdds_rank_level.getKey() + "]"  //人物等级提升或下降
//                     "[" + hdds_rank_leiji.getKey() + "]"
                //        神魔挑战
                //              "[" + DEVIL_FIGHT_ACTIVITY.getKey() + "]"+   //神魔挑战赛
                //         "[" + DEVIL_FIGHT_ENTER.getKey() + "]"+  //进入神魔挑战
                //        "[" + DEVIL_FIGHT_START.getKey() + "]"+  //开始神魔挑战
                //      "[" + DEVIL_FIGHT_BUY_TIME_LIST.getKey() + "]"+  //  购买挑战神魔时间   这个可以
                //         "[" + DEVIL_FIGHT_BUY_TIME_MONEY.getKey() + "]"+// 金币购买神魔时间
                //   "[" + DEVIL_FIGHT_BUY_TIME_GOLD.getKey() + "]" //元宝购买神魔时间

                ;

        String tail = "[离开/离开]";
        return content + tail;
    }


    public void level(Role role, String msg) {
        SpringUtils.getBean(GmCommandHandler.class).level(role, 70);
    }

    public void buyGold(Role role, String msg) {
        roleService.substractChargeScore(role, 15);
        roleService.addGold(role, 100000000, hdds_buy);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("购买元宝成功！！"));
    }

    public void buyMoney(Role role, String msg) {
        roleService.subtractGold(role, 1, Reason.BUY_MONEY);
        roleService.addMoney(role, 100000000, hdds_buy);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("购买金币成功！！"));
    }

    public void buyCjcfs(Role role, String msg) {
        short pos = SpringUtils.getBean(BagService.class).getPos(role, false);
        if (pos <= 0) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("背包已满"));
            return;
        }
        roleService.substractChargeScore(role, 1);
        SpringUtils.getEquipService().addMall("宠风散", true, role, 10);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("购买宠风散成功！！"));
    }

    public void buyCjxfs(Role role, String msg) {
        short pos = SpringUtils.getBean(BagService.class).getPos(role, false);
        if (pos <= 0) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("背包已满"));
            return;
        }
        if (msg.contains("10积分")) {
            roleService.substractChargeScore(role, 10);
            SpringUtils.getEquipService().addMall("超级仙风散", true, role, 100);
        } else {
            roleService.substractChargeScore(role, 1);
            SpringUtils.getEquipService().addMall("超级仙风散", true, role, 10);
        }
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("购买超级仙风散成功！！"));
    }

    public void buyZqhm(Role role, String msg) {
        short pos = SpringUtils.getBean(BagService.class).getPos(role, false);
        if (pos <= 0) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("背包已满"));
            return;
        }
        roleService.substractChargeScore(role, 1);
        SpringUtils.getEquipService().addMall("紫气鸿蒙", true, role, 10);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("购买紫气鸿蒙成功！！"));
    }

    public void rankLeiji(Role role, NPC npc) {
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());
        respNpcContent.setContent(SpringUtils.getBean(NewChargeActivityService.class).getShow(role));
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }

    public void inviteReward(Role role) {
        RoleConfirm roleConfirm = role.getConfirm();
        if (roleConfirm == null) {
            return;
        }
        if (roleConfirm instanceof InviteConfirm) {
        } else {
            return;
        }
        AccountService accountService = SpringUtils.getBean(AccountService.class);
        Account account = accountService.getAccount(role.getSid());
        List<Invite> list = accountService.queryInviteList(account.getUsername());
        if (list == null || list.size() <= 0) {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("没有可以领取的#R邀请奖励"));
            return;
        }
        int total = 0;
        for (Invite invite : list) {
            invite.setState(1);
            invite.setUpdatetime(new Date());
            accountService.updateInvite(invite);
            int rmb = invite.getRmb();
            rmb = (int) (rmb * 0.05);
            if (rmb < 5) {
                rmb = 5;
            }
            SpringUtils.getRoleService().addRechargeScore(role, rmb);
            total = total + rmb;
        }
        MessagePusher.pushMessage(role, new RespNotifyMiscEx("领取邀请奖励成功！！"));
        SpringUtils.getChatService().sendAdnotice("惊闻玩家#R" + role.getName() + "#n在#R活动大使#n处，领取邀请新玩家奖励#R" + total + "积分#n！真是可喜可贺！#51 #82");
    }

    /**
     * 转生 转世
     *
     * @param role
     */
    public void zhuansheng(Role role) {
        int zhuansheng = role.getExtendBox().getZhuansheng();
        int lv = Integer.parseInt(DataCache.REDIS_DATA.get("zhuansheng_lv"));
        String zhuansheng_item = DataCache.REDIS_DATA.get("zhuansheng_item");
        String zhuansheng_shuxing = DataCache.REDIS_DATA.get("zhuansheng_shuxing");
        int zhuansheng_max = Integer.parseInt(DataCache.REDIS_DATA.get("zhuansheng_max"));
        if (role.getLevel() >= lv) {
            PlayerExtendBox extendBox = role.getExtendBox();
            int zhuanshengNum = extendBox.getZhuansheng();
            if (zhuanshengNum < zhuansheng_max) {
                boolean flag = false;
                String msg = "";
                //检测消耗 是否满足要求
                String[] split = zhuansheng_item.split("\\+");
                for (String s : split) {
                    String[] split1 = s.split("-");
                    if ("物品".equals(split1[0])) {
                        String name = split1[1];
                        int stoneNum = equipService.getCount(name, false, role);
                        if (stoneNum < Integer.parseInt(split1[2])) {
                            flag = true;
                            msg = name + "不足" + Integer.parseInt(split1[2]) + "个";
                        }
                    } else if ("积分".equals(split1[0])) {
                        int jifen = Integer.parseInt(split1[1]);
                        if (role.getActivity().getRechargeScore() < jifen) {
                            flag = true;
                            msg = "积分不足" + Integer.parseInt(split1[1]);
                        }
                    }
                    if (flag) {
                        MessagePusher.pushMessage(role, new RespNotifyMiscEx(msg));
                        return;
                    }
                }
                //扣除物品 积分
                for (String s : split) {
                    String[] split1 = s.split("-");
                    if ("物品".equals(split1[0])) {
                        String name = split1[1];
                        int count = Integer.parseInt(split1[2]);
                        equipService.delRoloEquip(name, count, true, role);
                        MessagePusher.pushMessage(role, new RespNotifyMiscEx("扣除" + name + count + "个成功"));
                    } else if ("积分".equals(split1[0])) {
                        int jifen = Integer.parseInt(split1[1]);
                        roleService.substractChargeScore(role, jifen);
                    }
                }
                //发送属性。
                JSONArray titleJars = JSONObject.parseArray(zhuansheng_shuxing);
                for (Object titleJar : titleJars) {
                    JSONObject jsonObject = (JSONObject) titleJar;
                    String field = jsonObject.getString("field");
                    int num = jsonObject.getIntValue("value");
                    if ("所有相性".equals(field)) {
                        extendBox.setZhuanshengpolor(extendBox.getZhuanshengpolor() + num);
                    }
                    if ("所有属性".equals(field)) {
                        extendBox.setZhuanshengAttr(extendBox.getZhuanshengAttr() + num);
                    }
                }
                //转生次数+1
                extendBox.setZhuansheng(extendBox.getZhuansheng() + 1);
                //刷新任务
                roleService.zhuanshengAddPolorTask(role);
                //刷新属性
                zhuansheng +=1;
                //role.getExtendBox().setDuihuanchongwu1(zhuansheng);
                SpringUtils.getBean(RoleService.class).sendExtraAttribute(role);
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y恭喜转生成功，获得海量属性加成！！"+"最大转生次数#n#R"+zhuansheng_max+"#Y次#n"+"，#Y已经转生#n#R"+zhuansheng+"#Y次"));
            } else {
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y你已经达到转生的最大次数！！"));
            }
        } else {
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("你的等级不足 #Y" + lv + "级#n 不能进行转生"));
        }

    }

    public String checkItemNum(String item, Role role) {
        String msg = "";
        //检测消耗 是否满足要求
        String[] split = item.split("\\+");
        for (String s : split) {
            String[] split1 = s.split("-");
            if ("物品".equals(split1[0])) {
                String name = split1[1];
                int stoneNum = equipService.getCount(name, false, role);
                if (stoneNum < Integer.parseInt(split1[2])) {
                    msg = name + "不足" + Integer.parseInt(split1[2]) + "个";
                    return msg;
                }
            } else if ("积分".equals(split1[0])) {
                int jifen = Integer.parseInt(split1[1]);
                if (role.getActivity().getRechargeScore() < jifen) {
                    msg = "积分不足" + Integer.parseInt(split1[1]);
                    return msg;
                }
            }
        }
        return msg;
    }

    public void diffItemNum(String item, Role role) {
        String msg = "";
        //检测消耗 是否满足要求
        String[] split = item.split("\\+");
        //扣除物品 积分
        for (String s : split) {
            String[] split1 = s.split("-");
            if ("物品".equals(split1[0])) {
                String name = split1[1];
                int count = Integer.parseInt(split1[2]);
                equipService.delRoloEquip(name, count, true, role);
                MessagePusher.pushMessage(role, new RespNotifyMiscEx("扣除" + name + count + "个成功"));
            } else if ("积分".equals(split1[0])) {
                int jifen = Integer.parseInt(split1[1]);
                roleService.substractChargeScore(role, jifen);
            }
        }
    }

    /**
     * 周年卡
     *
     * @param role
     * @param npc
     */
    public void zhounianka(Role role, NPC npc) {

        List<MiJingShiLianEntity> query = dao.query(MiJingShiLianEntity.class, Cnd.NEW());
        if (CollectionUtil.isNotEmpty(query)) {
            MsgMiJingShiLian msgMiJingShiLian = new MsgMiJingShiLian();
            List<MiJingShiLianInfo> miJingShiLianInfoList = new ArrayList<>();
            int stoneNum = equipService.getCount("周年卡", false, role);
            msgMiJingShiLian.setScore(stoneNum);
            int bindId = 1;
            for (MiJingShiLianEntity miJingShiLianInfo : query) {

                String[] names = miJingShiLianInfo.getName().split("-");
                if (names.length >= 2) {
                    String name = names[1].split("\\$")[0];
                    MiJingShiLianInfo miJingShiLianInfo1 = new MiJingShiLianInfo();
                    miJingShiLianInfo1.setIndex((byte) miJingShiLianInfo.getId());
                    miJingShiLianInfo1.setName(name);
                    miJingShiLianInfo1.setCost(miJingShiLianInfo.getCost());
                    miJingShiLianInfo1.setNum((short) miJingShiLianInfo.getNum());
                    miJingShiLianInfo1.setBind(bindId++);
                    miJingShiLianInfoList.add(miJingShiLianInfo1);
                }
            }
            msgMiJingShiLian.setMiJingShiLianInfoList(miJingShiLianInfoList);
            MessagePusher.pushMessages(role, msgMiJingShiLian);

        }
    }

    /**
     * 碎片兑换物品
     * @param role
     * @param npc
     */
    public void suipianduihuan(Role role, NPC npc) {
        String suipianduihuan1 = DataCache.REDIS_DATA.get("suipianduihuan");
        JSONArray jar = JSONObject.parseArray(suipianduihuan1);
        StringBuffer sb = new StringBuffer();

        for (Object o : jar) {
           JSONObject obj  = (JSONObject) o;
            sb.append("[");
            sb.append(obj.getIntValue("num")+"个碎片兑换");
            sb.append(obj.getString("name"));
            sb.append("/");
            sb.append("spdhhd_");
            sb.append(obj.getString("name"));
            sb.append("]");
        }
        RespNpcContent respNpcContent = new RespNpcContent();
        respNpcContent.setNpcName(npc.getName());
        respNpcContent.setNpcId((int) npc.getId());

        String content = sb.toString();
        respNpcContent.setContent(content);
        respNpcContent.setNpcIcon(npc.getIcon());
        MessagePusher.pushMessage(role, respNpcContent);
    }
    public void suipianduihuan(Role role, String content) {
        String suipianduihuan1 = DataCache.REDIS_DATA.get("suipianduihuan");
        JSONArray jar = JSONObject.parseArray(suipianduihuan1);

        String name = content.replaceAll("spdhhd_","");
        for (Object o : jar) {
            JSONObject obj  = (JSONObject) o;
            if(name.equals(obj.getString("name"))){
                int num = obj.getIntValue("num");
                int count = this.equipService.getCount("万能碎片", false, role);
                if(count < num){
                    MessagePusher.pushMessage(role,new RespNotifyMiscEx("万能碎片不足"));
                    return;
                }
                equipService.delRoloEquip("万能碎片", num, false, role);

                SpringUtils.getBean(EquipService.class).addMall(name, true, role, 1);
                MessagePusher.pushMessage(role, new RespMsg("兑换"+name+"成功！"));

                break;
            }
        }
    }
}
